<?php
$datelastyear=	date("Y");
$datelastmonth=	date("m")-1;
$datethismonth=	date("m");

$months = array('1' => '01','2' => '02','3' => '03','4' => '04','5' => '05','6' => '06','7' => '07','8' => '08','9' => '09','10' => '10','11' => '11','12' => '12');

// heute
$orders_today = $db->db_query(" SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE o.date_purchased LIKE '".date("Y-m-d")."%' AND ot.orders_id = o.orders_id AND ot.class = 'ot_total' ");

// gestern
$orders_yesterday = $db->db_query(" SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE o.date_purchased LIKE '".date("Y-m-d",time() - 86400)."%' AND ot.orders_id = o.orders_id AND ot.class = 'ot_total' ");

// dieser Monat, alle
$orders_thismonth = $db->db_query(" SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE o.date_purchased LIKE '". date('Y') . "-" . date('m') . "%' AND ot.orders_id = o.orders_id AND ot.class = 'ot_total' ");

// letzer Monat, alle
$orders_lastmonth = $db->db_query("SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE o.date_purchased LIKE '".date("Y-m", (date('L') == 1 && date('n') == 3 ? time() - 29*3600*24 : time() - 30*3600*24)). "-%' AND ot.orders_id = o.orders_id AND ot.class = 'ot_total'");

// letzer Monat, ohne Status "Offen" und ohne UST
$orders_lastmonth_bereinigt = $db->db_query(" SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE o.orders_status NOT LIKE 1 AND o.date_purchased LIKE '".date("Y-m", (date('L') == 1 && date('n') == 3 ? time() - 29*3600*24 : time() - 30*3600*24)). "-%' AND ot.orders_id = o.orders_id AND ot.class = 'ot_total' ");

// alle
$orders_total = $db->db_query(" SELECT sum(ot.value) FROM ".TABLE_ORDERS." o, ".TABLE_ORDERS_TOTAL." ot WHERE ot.orders_id = o.orders_id AND ot.class = 'ot_total' ");

require_once(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.price.php');
$statisticsPrice = new price($_SESSION['currency'], $_SESSION['customers_status']['customers_status_id'], $db);

?>
<table width="100%" class="dataTable">
	<tr>
		<td style="background:#FCF5DD">Umsatz heute:</td>
		<td  style="background:#FCF5DD" align="right"> <?php echo $statisticsPrice->format($orders_today->fields['sum(ot.value)'], true); ?></td>
	</tr>
	<tr>
		<td style="background:#FCF5DD">Umsatz gestern:</td>
		<td style="background:#FCF5DD" align="right"><?php echo $statisticsPrice->format($orders_yesterday->fields['sum(ot.value)'], true); ?></td>
	</tr>
	<tr>
		<td style="background:#FCF5DD">aktueller Monat:</td>
		<td style="background:#FCF5DD" align="right"> <?php echo $statisticsPrice->format($orders_thismonth->fields['sum(ot.value)'], true); ?></td>
	</tr>
	<tr>
		<td style="background:#F1F1F1">letzter Monat (alle):</td>
		<td style="background:#F1F1F1" align="right"><?php echo $statisticsPrice->format($orders_lastmonth->fields['sum(ot.value)'], true); ?></td>
	</tr>
	<tr>
		<td style="background:#F1F1F1">letzter Monat (bezahlt):</td>
		<td style="background:#F1F1F1" align="right"><?php echo $statisticsPrice->format($orders_lastmonth_bereinigt->fields['sum(ot.value)'], true); ?></td>
	</tr>
	<tr>
		<td style="background:#E8E8E8">Umsatz gesamt:</td>
		<td style="background:#E8E8E8" align="right"><?php echo $statisticsPrice->format($orders_total->fields['sum(ot.value)'], true); ?></td>
	</tr>
</table>